package com.gxa.controller.xxh.providermanagement;

import com.gxa.common.R;
import com.gxa.common.Status;
import com.gxa.common.vo.AdvanceSearchProviderCondition;
import com.gxa.common.vo.Provider;
import com.gxa.common.vo.TransProvider;
import com.gxa.service.ProviderManagementService;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


/**
* 供应商管理
*
* */
@Controller
@Api(value = "供应商管理",tags = "供应商管理API")
@RequestMapping("/providerManagement/providerManagement")
@RequiresRoles(value = {"超级管理员","院长"},logical = Logical.OR)
public class ProviderManagementController {

    @Autowired
    ProviderManagementService providerManagementService;

    /**
     * 分页查询供应商列表信息
     */
    @RequestMapping(value = "/findProviderList",method = RequestMethod.GET)
    @ApiOperation(value = "展示所有供应商接口",notes = "查询所有供应商信息",httpMethod = "GET",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数默认第一页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",paramType = "query",dataType = "String",required = true)
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R findProviderList(@RequestParam("currentPage") Integer currentPage, @RequestParam("pageSize")Integer pageSize){
        return providerManagementService.findProviderList(currentPage,pageSize);

    }

    /**
     * 新增一条供应商
     */
    @RequestMapping(value = "/addProvider",method = RequestMethod.POST)
    @ApiOperation(value = "新增供应商接口",notes = "新增一个供应商",httpMethod = "POST",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R addProvider(@RequestBody @ApiParam(name = "provider",value = "供应商全部字段",required = true) Provider provider){
        return providerManagementService.addProvider(provider);
    }

    /**
     * 通过ID进行供应商批量转交
     */
    @RequestMapping(value = "/updateUserIdByIds",method = RequestMethod.POST)
    @ApiOperation(value = "通过ID进行供应商批量转交接口",notes = "通过ID进行供应商批量转交",httpMethod = "POST",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R transProvider(@RequestBody @ApiParam(name = "transProvider",value = "批量转交供应商实体") TransProvider transProvider){
        R r = new R();
        boolean b = providerManagementService.transProvider(transProvider);
        if(b == true){
            r.fromStatus(Status.SUCCESS);
        }else {
            r.setCode(500);
            r.setMsg("转交失败");
        }
        return r;
    }

    /**
     * 高级查询供应商信息
     */
    @RequestMapping(value = "/advanceSearchProvider",method = RequestMethod.POST)
    @ApiOperation(value = "高级查询供应商信息",notes = "高级查询供应商信息",httpMethod = "POST",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R advanceSearchProvider(@RequestBody @ApiParam(name = "advanceSearchProviderCondition",value = "高级查询转交供应商实体") AdvanceSearchProviderCondition advanceSearchProviderCondition){
        System.out.println(advanceSearchProviderCondition.getStatus());

        System.out.println(advanceSearchProviderCondition.getType());
        return providerManagementService.advanceSearchProvider(advanceSearchProviderCondition);
    }

    /**
     *条件查询供应商信息
     */
    @RequestMapping(value = "/findProvider",method = RequestMethod.POST)
    @ApiOperation(value = "条件查询供应商信息",notes = "条件查询供应商信息", httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数默认第一页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "findProviderCondition",value = "条件",paramType = "query",dataType = "String",required = true)
    })
    @ResponseBody
    public R findProvider(@RequestParam("findProviderCondition") String findProviderCondition, Integer currentPage,Integer pageSize){
        return providerManagementService.selectProviderByQuery(currentPage,pageSize,findProviderCondition);
    }

    /**
     * 根据供应商ID修改供应商信息
     */
    @ApiOperation(value = "根据供应商ID修改供应商信息",notes = "根据供应商ID修改供应商信息", httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @RequestMapping(value = "/updateProviderById",method = RequestMethod.POST)
    @ResponseBody
    public R updateProviderById(@RequestBody @ApiParam(name = "provider",value = "供应商全部字段",required = true) Provider provider){

        return providerManagementService.updateProvider(provider);
    }

    /**
     * 根据供应商ID删除供应商
     */
    @ApiOperation(value = "根据供应商ID删除供应商",notes = "根据供应商ID删除供应商",
            httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "供应商ID",dataType = "String",required = true)
    })
    @RequestMapping(value = "/deleteProviderById",method = RequestMethod.POST)
    @ResponseBody
    public R deleteProviderById(@RequestParam("id")Integer id){
        return providerManagementService.deleteProviderById(id);
    }

    /**
     * 查询模糊
     * @param currentPage
     * @param pageSize
     * @param findProviderCondition
     * @return
     */
    @RequestMapping(value = "/findProviderByQuery",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "模糊查询供应商",notes = "模糊查询供应商", httpMethod = "GET", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数默认第一页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "findProviderCondition",value = "条件",paramType = "query",dataType = "String",required = true)
    })
    public R findProviderByQuery(Integer currentPage,Integer pageSize,String findProviderCondition){
        return providerManagementService.selectProviderByQuery(currentPage,pageSize,findProviderCondition);
    }




}
